package com.sike.javacore.serializer.serializable;

import com.sike.javacore.serializer.serializable.dto.Person_1;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Serializable03 {

    public static void main(String[] args) throws Exception {
        // 先序列化
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("person_1.txt"));
        Person_1 person = new Person_1("王五",32,180F);
        oos.writeObject(person);
        System.out.println("原对象：" + person);

        // 再反序列化
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("person_1.txt"));
        Person_1 person1 = (Person_1) ois.readObject();
        System.out.println("序列化后对象：" + person1);
    }
}
